package org.noka.nokatabmenu;

import java.io.IOException;

import javax.servlet.jsp.JspException;

import org.nokatag.system.BugInfoWrint;
import org.nokatag.tagjava.BodyNokaTag;

public class NTabItem extends  BodyNokaTag{
	private static final long serialVersionUID = -4217614790436084994L;
	public String id = null;//选项卡id
	public String title = null;//标题
	
	public String open = null;//选中
	public String url = null;//url，可以为空
	
	public int doStartTag()throws JspException{
		try{
			Object obj = this.getParent();
			if(obj instanceof NTab){ 
				NTab ntab = (NTab)obj;
				StringBuilder body = new StringBuilder();
				if(null!=url){
					body.append("<iframe id=\""+ntab.getId()+"_body_iframe_"+id+"\" frameborder=\"no\" border=\"0\" name=\""+ntab.getId()+"_body_iframe_"+id+"\" style=\"border:0\"  src=\""+url+"\"></iframe>");
				}else{
					body.append("<div style=\"clear: both;\"></div><div style=\"width:100%;height:100%\" id=\""+ntab.getId()+"_body_divhtml_"+id+"\">");
				}
				pageContext.getOut().write(body.toString());
				if(null!=open && "true".equals(open)){
					ntab.setOptab(id);
				}
				ntab.insertTab(new TabItem(id, title, null, open, url));
			}
		}catch(Exception se){
			 BugInfoWrint.Print(se);
		}
		return EVAL_BODY_INCLUDE;
	}
	
	public int doEndTag() throws JspException {
		if(null==url){
			try {
				pageContext.getOut().write("</div>".toString());
			} catch (IOException e) {
			}
		}
        return EVAL_PAGE;
	 }
	
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	
	public String getOpen() {
		return open;
	}
	public void setOpen(String open) {
		this.open = open;
	}
	public String getUrl() {
		return url;
	}
	public void setUrl(String url) {
		this.url = url;
	}

}
